<!-- 加工抽检 -->
<template>
  <div class="mod-config">
    <el-button-group style="margin-bottom: 10px;">
      <el-button type="primary" icon="el-icon-search" @click="searchHandle">查找</el-button>
      <el-button type="primary" icon="el-icon-delete" @click="searchReset">清空</el-button>
    </el-button-group>
    <el-form inline label-width="100px" @keyup.enter.native="searchHandle">
      <el-form-item label="配镜单号">
        <el-input v-model="dataForm.saleBillId"></el-input>
      </el-form-item>
      <el-form-item label="加工师">
        <el-input v-model="dataForm.workUserId"></el-input>
      </el-form-item>
      <el-form-item label="检验日期">
        <el-row>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.spotCheckTimeMin" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
          <el-col class="line" :span="2" style="text-align: center;">-</el-col>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.spotCheckTimeMax" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="检验师">
        <el-input v-model="dataForm.spotCheckUserId"></el-input>
      </el-form-item>
      <el-form-item label="销售门店">
        <el-input v-model="dataForm.saleDeptId"></el-input>
      </el-form-item>
      <el-form-item label="销售日期">
        <el-row>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.createTimeMin" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
          <el-col class="line" :span="2" style="text-align: center;">-</el-col>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.createTimeMax" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="顾客姓名">
        <el-input v-model="dataForm.customerName"></el-input>
      </el-form-item>
      <el-form-item label="取镜日期">
        <el-row>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.takeMirroTimeMin" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
          <el-col class="line" :span="2" style="text-align: center;">-</el-col>
          <el-col :span="11">
            <el-date-picker v-model="dataForm.takeMirroTimeMax" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>

    <div class="avue-crud">
      <el-table :data="dataList" border v-loading="dataListLoading" :max-height="tableHeight">
        <el-table-column prop="saleBillId" label="配镜单号">
          <template slot-scope="scope">
            <el-link type="primary" @click="checkDetailByOrder(scope.row.saleBillId)">{{scope.row.saleBillId}}</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="customerName" label="顾客姓名"></el-table-column>
        <el-table-column prop="workUserId" label="加工师"></el-table-column>
        <el-table-column prop="spotCheckName" label="检验师"></el-table-column>
        <el-table-column prop="spotCheckTime" label="检验时间"></el-table-column>
        <el-table-column prop="takeMirroTime" label="取镜时间"></el-table-column>
        <el-table-column label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-edit" @click="getDetails(scope.row.saleId)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="avue-crud__pagination">
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next"></el-pagination>
    </div>
    <order-info v-if="infoVisible" ref="infoDialog"></order-info>
  </div>
</template>

<script>
  import { mapGetters } from "vuex"
  import { workSpotCheckFetchList } from "@/api/eims/spot-check"

  import OrderInfo from '@/views/eims/optician/glassesinfo/detail'
  export default {
    data() {
      return {
        dataForm: {},
        dataList: [],
        dataListLoading: false,
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        infoVisible: false
      };
    },
    created() {
      this.getDataList();
    },
    computed: {
      ...mapGetters(["permissions"]),
      tableHeight: function(){
        return window.innerHeight - 260
      }
    },
    components: {
      OrderInfo
    },
    methods: {
      //  查询数据
      searchHandle() {
        this.pageIndex = 1
        this.getDataList()
      },
      //  清空搜索表单
      searchReset() {
        for (let key in this.dataForm) {
          this.dataForm[key] = ''
        }
      },
      getDataList() {
        this.dataListLoading = true;
        let params = {
          current: this.pageIndex,
          size: this.pageSize
        };
        workSpotCheckFetchList(Object.assign(params, this.dataForm)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getDataList();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getDataList();
      },
      //  查看配镜单详情
      checkDetailByOrder(order) {
        this.infoVisible = true;
        this.$nextTick(() => {
          this.$refs.infoDialog.init('', order, '配镜单详情');
        });
      },
    }
  };
</script>
